package com.sdwz.borrow.controller;


import com.sdwz.borrow.client.UserClient;
import com.sdwz.borrow.entity.BookInfo;
import com.sdwz.borrow.entity.UserInfo;
import com.sdwz.borrow.entity.vo.BorrowInfoVo;
import com.sdwz.borrow.service.BorrowInfoService;
import com.sdwz.commonutil.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 借阅信息表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/admin/borrow")
public class BorrowInfoController {

    @Autowired
    BorrowInfoService borrowInfoService;
    @Autowired
    UserClient userClient;
    /**
     * 取书（预约表状态改为完成借阅，借阅表中添加借阅信息）
     * @param appoId
     * @return
     */
    @PostMapping("/getbook/{appoId}")
    public Result getBook(@PathVariable String appoId){
        borrowInfoService.getBook(appoId);
        return Result.ok();
    }

    /**
     * 查询借阅记录列表
     * @param current
     * @param limit
     * @param borrowInfoVo
     * @return
     */
    @GetMapping("/list/{current}/{limit}")
    public Result getBorrowInfoList(@PathVariable Long current,
                                    @PathVariable Long limit,
                                    BorrowInfoVo borrowInfoVo){
        Map<String,Object> result = borrowInfoService.getBorrowInfoList(current,limit,borrowInfoVo);
        return Result.ok(result);
    }

    /**
     * 查询借阅记录列表
     * @param current
     * @param limit
     * @param borrowInfoVo
     * @return
     */
    @GetMapping("/in/{current}/{limit}")
    public Result getInInfo(@PathVariable Long current,
                                    @PathVariable Long limit,
                                    BorrowInfoVo borrowInfoVo){
        Map<String,Object> result = borrowInfoService.getInList(current,limit,borrowInfoVo);
        return Result.ok(result);
    }

    /**
     * 确认还书
     * @param borrowId
     * @return
     */
    @PostMapping("/confirmReturnBook/{borrowId}")
    public Result confirmReturnBook(@PathVariable String borrowId){
        borrowInfoService.confirmBook(borrowId);
        return Result.ok();
    }

    /**
     * 确认还书
     * @param borrowId
     * @return
     */
    @PostMapping("/confirmReturnTimeOutBook/{borrowId}")
    public Result confirmReturnTimeOutBook(@PathVariable String borrowId){
        borrowInfoService.confirmTimeOutBook(borrowId);
        return Result.ok();
    }

}

